﻿<UserControl x:Class="MusicExplorer.View.WebRepositoryTree"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:wrappers="clr-namespace:MusicExplorer.Wrappers"
             xmlns:controls="clr-namespace:MusicExplorer.Resources.Control"
             xmlns:internals="clr-namespace:MusicExplorer.Internals" DataContext="{Binding WebRepositoryTree}"
             >
    
    <UserControl.Resources>
        <ResourceDictionary>
            <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
            <internals:BooleanToVisibilityInvertConverter x:Key="BooleanToVisibilityInvertConverter" />
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Resources/Skins/TreeViewSkin.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

    <StackPanel Orientation="Vertical" VerticalAlignment="Stretch">
        <ListBox ItemsSource="{Binding WebRepositories}" Style="{StaticResource ListBoxWebRepository}" MinWidth="210" x:Name="listWebRepositories" PreviewMouseDown="ListChanged">
            <ListBox.ItemContainerStyle>
                <Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="IsSelected" Value="{Binding IsSelected}" />
                </Style>
            </ListBox.ItemContainerStyle>
            <ListBox.Resources>
                <DataTemplate DataType="{x:Type wrappers:WebRepositoryWrapper}">
                    <Grid Height="25">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <controls:LoadingTreeviewIndicator VerticalAlignment="Center" Visibility="{Binding IsLoading, Converter={StaticResource BooleanToVisibilityConverter}}" />
                        <Image Width="16" Height="16" VerticalAlignment="Center" Source="{Binding DisplayIcon}"
                                       Visibility="{Binding IsLoading, Converter={StaticResource BooleanToVisibilityInvertConverter}}" />
                        <TextBlock Margin="5, 0, 0, 0" Grid.Column="1" VerticalAlignment="Center" Text="{Binding DisplayName}" />
                    </Grid>
                </DataTemplate>
            </ListBox.Resources>
        </ListBox>
        
        <Separator />
    
        <TreeView ItemsSource="{Binding GroupsWebRepositories}" Style="{StaticResource TreeViewWebRepository}" Width="300" SelectedItemChanged="GroupChanged" x:Name="treeWebRepositories">
            <TreeView.Resources>
                <HierarchicalDataTemplate DataType="{x:Type wrappers:WebRepositoryGroupWrapper}" ItemsSource="{Binding WebRepositories}">
                    <HierarchicalDataTemplate.ItemContainerStyle>
                        <Style TargetType="{x:Type TreeViewItem}">
                            <Setter Property="IsSelected" Value="{Binding IsSelected}" />
                            <Setter Property="IsExpanded" Value="{Binding IsExpanded}" />
                        </Style>
                    </HierarchicalDataTemplate.ItemContainerStyle>
                    <Grid Height="25" Width="224">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Image Width="16" Height="16" VerticalAlignment="Center" Source="{Binding DisplayIcon}" />
                        <TextBlock Margin="5, 0, 0, 0" Grid.Column="1" VerticalAlignment="Center" Text="{Binding DisplayName}" />
                        <Button Content="Manage" Grid.Column="2" Command="{Binding ManageWebRepositories}" />
                    </Grid>
                </HierarchicalDataTemplate>
                <DataTemplate DataType="{x:Type wrappers:WebRepositoryWrapper}">
                    <Grid Height="25">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <controls:LoadingTreeviewIndicator VerticalAlignment="Center" Visibility="{Binding IsLoading, Converter={StaticResource BooleanToVisibilityConverter}}" />
                        <Image Width="16" Height="16" VerticalAlignment="Center" Source="{Binding DisplayIcon}"
                                       Visibility="{Binding IsLoading, Converter={StaticResource BooleanToVisibilityInvertConverter}}" />
                        <TextBlock Margin="5, 0, 0, 0" Grid.Column="1" VerticalAlignment="Center" Text="{Binding DisplayName}" />
                    </Grid>
                </DataTemplate>
            </TreeView.Resources>
        </TreeView>
    </StackPanel>
</UserControl>
